var columns = [{
    checkbox: true
},
{
    field: "accountName",
    title: "账户名",
    titleTooltip:"accountName"
},
{
    field: "userName",
    title: "姓名"
},
{
    field: "company.companyName",
    title: "公司名称"
},
{
    field: "dept.deptName",
    title: "部门"
},
{
    field: "role.name",
    title: "角色"
},
{
    field: "email",
    title: "邮箱"
},
{
    field: "deleteStatus",
    visible: false,
    title: "是否删除",
    formatter: function(value, row, index) {
        if (value == 1) {
            return '是';
        } else {
            return '否';
        }
    }
},
{
    field: "locked",
    visible: false,
    title: "是否锁定",
    formatter: function(value, row, index) {
        if (value == 1) {
            return '是';
        } else {
            return '否';
        }
    }
},
{
    field: "isValid",
    title: "是否有效",
    formatter: function(value, row, index) {
        if (value == 1) {
            return '有效';
        } else {
            return '失效';
        }
    }
},

{
    field: "creatorName",
    title: "创建者"
},
{
    field: "createTime",
    title: "创建时间",
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd hh:mm:ss");
        //return value!=null && value!=""?new Date(value).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''):null;
    }
},
{
    field: "updateTime",
    title: "更新时间",
    visible: false,
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd hh:mm:ss");
        //return value!=null && value!=""?new Date(value).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''):null;
    }
}];
function queryParams(params) {
    var param = {
        pageNumber: params.pageNumber,
        pageSize: params.pageSize,
        keyword: $('.search input').val()
    };
    return param;
}
var user_table = $('#user_table'); //通过table id获取需要初始化的table
//初始化的table
initTable(user_table, $('#user_toolbar'), 'user/list', columns, queryParams, 'zh-CN', true);

//给搜索框添加提示
$('.search input').attr("placeholder", "搜索账户名/姓名");

function resetPassword() {
    var ids = getSelections(user_table, 'id');
    if (ids.length == 1) {
        loadPage('user/' + ids.toString() + '/toRestPassword');
    } else {
        layer.msg("你没有选择行或选择了多行数据", {
            icon: 0
        });
    }
}

function btnDel() {
    var ids = getSelections(user_table, 'id');
    if (ids.length == 0) {
        layer.msg("请选择要删除的记录", {
            icon: 0
        });
    } else {
        layer.confirm('确定删除所选记录？', {
            icon: 3
        },
        function(index) {
            $.ajax({
                type : "DELETE",
                url :  "user/" + ids.toString() + "/delete/",
                dataType : "json",
                success : function(result) {
                    if (result['status'] == 0) {
                        layer.msg(result['message'], {
                            icon : 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        refreshDelTable(user_table, ids.length);
                    } else {
                        layer.msg(result['message'], {
                            icon : 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                },
                error : function(errorMsg) {
                    layer.msg('服务器未响应,请稍后再试', {
                        icon : 3,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                }
            });
        });
    }
}

function btnEdit() {
    var ids = getSelections(user_table, 'id');
    if (ids.length == 1) {
        loadPage('user/' + ids.toString() + '/select');
    } else {
        layer.msg("你没有选择行或选择了多行数据", {
            icon: 0
        });
    }
}